cmake_minimum_required(VERSION 3.14)

project(tensorrt-gpu-win-msvc2019 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# opencv
# windows
# set(OpenCV_DIR "C:/Program Files/opencv460/install/vs2022/x64/vc17/lib")
# find_package(OpenCV)
# linux
set(OpenCV_DIR "/home/tacom/Development/Mounts/Envs/opencv_490_gpu/lib/cmake/opencv4/")
find_package(OpenCV)

# tensorrt
# windows
# set(Tensorrt_DIR "C:/Program Files (x86)/NVIDIA Corporation/TensorRT-101")
# set(Tensorrt_INCLUDE_DIRS ${Tensorrt_DIR}/include)
# set(Tensorrt_LIB_DIRS ${Tensorrt_DIR}/lib)
# set(Tensorrt_LIBS
#    ${Tensorrt_LIB_DIRS}/nvinfer_10.lib
#    ${Tensorrt_LIB_DIRS}/nvinfer_plugin_10.lib
# )
# linux
set(Tensorrt_INCLUDE_DIRS "/usr/include/x86_64-linux-gnu")
set(Tensorrt_LIB_DIRS "/usr/lib/x86_64-linux-gnu")
set(Tensorrt_LIBS
    ${Tensorrt_LIB_DIRS}/libnvinfer.so
    ${Tensorrt_LIB_DIRS}/libnvinfer_plugin.so
)

# cuda 11.8
# windows
# set(libcudacxx_BASE "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8")
# set(libcudacxx_DIR "${libcudacxx_BASE}/lib/cmake/libcudacxx")
# find_package(libcudacxx)
# set(CUDA_LIBS
#     "${libcudacxx_BASE}/lib/x64/cudart.lib"
# )
# linux
set(libcudacxx_DIR "/usr/local/cuda/lib64/cmake/libcudacxx")
find_package(libcudacxx)
set(CUDA_LIBS
    /usr/local/cuda/lib64/libcudart.so
)

# qt6 package
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)

add_executable(tensorrt-gpu-win-msvc2019
    main.cpp
    Network/NetworkTools.h Network/NetworkTools.cpp
    Network/DenseGradeWrapper.h Network/DenseGradeWrapper.cpp
    Network/NvLogger.h Network/NvLogger.cpp
)

target_include_directories(tensorrt-gpu-win-msvc2019
    PRIVATE
        ${OpenCV_INCLUDE_DIRS}
        ${Tensorrt_INCLUDE_DIRS}
        .
)
target_link_libraries(tensorrt-gpu-win-msvc2019
    Qt${QT_VERSION_MAJOR}::Core
    libcudacxx::libcudacxx
    ${CUDA_LIBS}
    ${OpenCV_LIBS}
    ${Tensorrt_LIBS}
)

include(GNUInstallDirs)
install(TARGETS tensorrt-gpu-win-msvc2019
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
